/*
	File:		Geometry.h
	Author:		dmonroe
	Date:		11/9/2012
	Copyright:	Full Sail University

	Purpose:	Rectangles and Points
*/

#ifndef GEOMETRY_H
#define GEOMETRY_H

struct SPoint
{
	long	x;
	long	y;
};

struct SRect
{
	long	left;
	long	top;
	long	right;
	long	bottom;
};

inline void SetRect( SRect& rect, long left, long top, long right, long bottom )
{
	rect.left	= left;
	rect.top	= top;
	rect.right	= right;
	rect.bottom	= bottom;
}

inline void OffsetRect( SRect& rect, long x, long y )
{
	rect.left	+= x;
	rect.top	+= y;
	rect.right	+= x;
	rect.bottom	+= y;
}

inline bool IntersectRect( const SRect& rect1, const SRect& rect2 )
{
	return ( (rect1.left <= rect2.right) && (rect1.right >= rect2.left) && (rect1.top <= rect2.bottom) && (rect1.bottom >= rect2.top) );
}

inline bool IntersectRect( const SRect& rect1, const SRect& rect2, SRect& overlap )
{
	overlap.top		= (rect1.top > rect2.top)		? rect1.top		: rect2.top;		// max
	overlap.left	= (rect1.left > rect2.left )	? rect1.left	: rect2.left;		// max
	overlap.bottom	= (rect1.bottom < rect2.bottom) ? rect1.bottom	: rect2.bottom;		// min
	overlap.right	= (rect1.right < rect2.right)	? rect1.right	: rect2.right;		// min

	return ( (overlap.bottom - overlap.top > 0) && (overlap.right - overlap.left > 0) );
}

inline bool PointInRect( const SPoint& point, const SRect& rect )
{
	return ( (point.x <= rect.right) && (point.x >= rect.left) && (point.y <= rect.bottom) && (point.y >= rect.top) );
}

#endif //GEOMETRY_H
